UIStepper = {}
UIStepperFunc = {}
UIStepperFunc.__index = UIStepperFunc
setmetatable(UIStepper, UIStepperFunc)

UIStepperFunc.create = function(self, leftButton, rightButton, action, target)
  local l = {}
  setmetatable(l, UIStepperFunc)
  setObjectExtTable(leftButton, l)
  setObjectExtTable(rightButton, l)
  l.target = target
  l.action = action
  l.leftButton = leftButton
  l.rightButton = rightButton
  l.index = 0
  return l
end
UIStepperFunc.setCount = function(self, count)
  self.count = count
  self:setState()
end
UIStepperFunc.setIndex = function(self, index)
  self.index = index 
  self:setState()
end
UIStepperFunc.setState = function(self)
  print("UIStepperFunc.setState", self.index)
  self.leftButton:setEnabled(true)
  self.rightButton:setEnabled(true)
  if self.index==0 then
    self.leftButton:setEnabled(false)
  end
  if self.index==self.count-1 then
    self.rightButton:setEnabled(false)
  end
  local metaFunc = getmetatable(self.target)
  metaFunc[self.action](self.target, self.index)
end

UIStepperFunc.onButtonDown = function(self, node, event)
  if node==self.leftButton then
    self.index=self.index-1 
  else
    self.index=self.index+1 
  end
  self:setState()
end
